const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')

let maybe = Maybe.of([5, 6, 1])

// 练习1
let ex1 = (num) => {
    maybe = maybe.map(v => fp.map(x => fp.add(x, num), v))
    return maybe._value
}
// console.log(ex1(3))

// 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti'])
let ex2 = () => {
    xs = xs.map(v => fp.first(v))
    return xs._value
}
// console.log(ex2())

// 练习3
let safeProp = fp.curry(function(x, o){
    return Maybe.of(o[x])
})
let user = {id: 2, name: 'Albert'}
let ex3 = () => {
    let firstLetter = Container.of(user)
        .map(v => safeProp('name')(v)._value)
        .map(v => fp.first(v))
    return firstLetter._value
}
// console.log(ex3())

// 练习4
// let ex4 = function(n) {
//     if(n) {
//         return parseInt(n)
//     }
// }

let ex4 = (n) => {
    let parseIntNew = Maybe.of(n)
        .map(v => parseInt(v))
    return parseIntNew._value
}
// console.log(ex4('123'))
// console.log(ex4())